home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRNOMY / AA_51.ZIP / VEARTH.C < prev    next >
C/C++ Source or Header  |  1993-02-09  |  1KB  |  56 lines

  1.  
  2. /* Calculate the velocity vector of the earth
  3.  * as it moves in its elliptical orbit.
  4.  * The difference in velocity between this and assuming
  5.  * a circular orbit is only about 1 part in 10**4.
  6.  *
  7.  * Note that this gives heliocentric, not barycentric, velocity.
  8.  *
  9.  * Input is Julian date.  Output left in global array vearth[].
  10.  */
  11.  
  12. double jvearth = -1.0;
  13. double vearth[3] = {0.0};
  14.  
  15. #include "kep.h"
  16.  
  17. extern struct orbit earth;
  18.  
  19. int velearth( J )
  20. double J;
  21. {
  22. double e[3], p[3], t;
  23. int i;
  24. #if DEBUG
  25. double x[3], A, q;
  26. #endif
  27.  
  28. if( J == jvearth )
  29.     return(0);
  30.  
  31. jvearth = J;
  32.  
  33. /* calculate heliocentric position of the earth
  34.  * as of a short time ago.
  35.  */
  36. t = 0.005;
  37. kepler( TDT-t, &earth, e, p );
  38.  
  39. for( i=0; i<3; i++ )
  40.     vearth[i] = (rearth[i] - e[i])/t;
  41.  
  42. #if DEBUG
  43. /* Generate display for comparison with Almanac values. */
  44. for( i=0; i<3; i++ )
  45.     {
  46.     q = vearth[i];
  47.     A += q*q;
  48.     x[i] = q;
  49.     }
  50. A = sqrt(A);
  51. precess( x, TDT, 1 );
  52. printf( "Vearth %.6e, X %.6lf, Y %.6lf, Z %.6lf\n", A, x[0], x[1], x[2] );
  53. #endif
  54. return(0);
  55. }
  56.